package com.xsz.service;

import java.util.List;
import java.util.Random;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xsz.entity.User;
import com.xsz.repository.UserRepository;
import com.xsz.util.KeyUtil;

@Service
public class UserService {
	@Resource
	UserRepository userRepository;
	
	public User add(User user) {
		user.setId(KeyUtil.getId());
		return userRepository.save(user);
	}
	
	
	public List<User> getAll() {
		return userRepository.findAll();
	}
	
	public User login(String name,String pwd) {
		return userRepository.findByNameAndPwd(name, pwd);
	}
	
	public List<User> likeName(String name) {
		return userRepository.findByNameLike(name+"%");
	}

}
